home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 274_01.zip / A_TESTF.C < prev    next >
Text File  |  1993-04-01  |  2KB  |  106 lines

  1. /* Array Handling Package
  2. (C) Copyright 1985,1987,1988 James P. Cruse - All Rights Reserved
  3.  
  4. a_testf.c  
  5.  
  6. A Part of the User-Supported Array Handling package. Please see
  7. the file ARRAY.h for discussion concerning the registration and 
  8. usage of the package.
  9.  
  10. This program does a Quick test of some of the Array Package routines.
  11.  
  12. Tests using floating point operations.
  13.  
  14. Numerically proves that sin^2+cos^2 = 1.
  15.  
  16. */    
  17.  
  18. #include <stdio.h>
  19. #include <math.h>
  20.  
  21. #include "array.h"
  22.  
  23. #define     ARRSIZE        100     /* Number of Elements in Array */
  24.  
  25. /* global arrays */
  26. double    sin_array[ARRSIZE];
  27. double     cos_array[ARRSIZE];
  28. double    sum_array[ARRSIZE];
  29.  
  30.  
  31. /* get 2pi */
  32. #define    PI2    (2*3.1415)
  33.  
  34. main()
  35. {
  36. double sum;
  37.  
  38. /* Test whether or not your compile can handle curly braces without */
  39. /* having a conditional prior to them */
  40. /* If your compiler generates an error, try replacing ARR_IF_NEEDED */
  41. /* with 1 in array.h */
  42.  
  43. ARR_IF1
  44. {        
  45. sum = 1.0*ARRSIZE;        /* do something */
  46. } ARR_IF2
  47.  
  48.  
  49. printf("Test the Hypothesis sin^2 + cos^2 = 1.\n");
  50. printf("\nMake 2 arrays, sin^2 and cos^2, then sum to verify.\n");
  51. printf("If sin^2 + cos^s = 1, then summing all should result in the\n");
  52. printf("Length of the Arrays\n");
  53.  
  54. printf("Filling Arrays...\n");
  55.  
  56. /* lets first fill the arrays */
  57. a_ifill(ARRSIZE,sin_array,0.0,PI2);
  58. a_ifill(ARRSIZE,cos_array,0.0,PI2);
  59.  
  60.  
  61. printf("Getting Sines and Cosines\n");
  62.  
  63. /* now get the sin & cos */
  64. a_fun(ARRSIZE,sin_array,sin_array,sin);        /* sin defined in math.h */
  65. a_fun(ARRSIZE,cos_array,cos_array,cos);        /* cos defined in math.h */
  66.  
  67.  
  68. printf("Squaring\n");
  69.  
  70. /* now square */
  71. aa_mul(ARRSIZE,sin_array,sin_array,sin_array);
  72. aa_mul(ARRSIZE,cos_array,cos_array,cos_array);
  73.  
  74. printf("Adding\n");
  75.  
  76. /* now sum the two arrays */
  77. aa_add(ARRSIZE,sum_array,sin_array,cos_array);
  78.  
  79.  
  80. printf("Display some Values\n");
  81.  
  82. /* now display the some of them */
  83. printf("Results: [0] = %f, [1] = %f, [%d] = %f, [%d] = %f\n",    \
  84.     sum_array[0],sum_array[1],ARRSIZE/2,sum_array[ARRSIZE/2],    \
  85.     ARRSIZE-1,sum_array[ARRSIZE-1]);
  86.  
  87.  
  88. printf("Now Summing all sin^2 + cos^2\n");
  89.  
  90. /* now add them all up */
  91. a_sum(ARRSIZE,sum,sum_array);
  92.  
  93.  
  94. printf("Results:\n");
  95.  
  96. /* now results are? */
  97. printf("Total: %f, Size %f, Total/Size %f, Total-Size %f\n",    \
  98.     sum,(double)ARRSIZE,sum/ARRSIZE,sum-ARRSIZE);
  99.  
  100.  
  101. /* QED */
  102. printf("\nQED\n");
  103.  
  104. exit(0);
  105. }
  106.